use std::sync::{Arc, Mutex};
use lazy_static::lazy_static;
use crate::utils;
use super::thread_pool::SimplePool;


pub trait SingleInit<T> {
    fn single_const() -> Arc<T>;
    fn single_mut() -> Arc<Mutex<T>>;
}

#[allow(non_snake_case)]
#[macro_export]
macro_rules! single_create {

    ($type:ty, $($args:expr),*)=>{
        impl crate::utils::singleton::SingleInit<$type> for $type {
 fn single_const() -> std::sync::Arc<$type> {
    static mut POOL: core::option::Option<std::sync::Arc<$type>> = None;
    unsafe {
        POOL.get_or_insert_with(move ||
            std::sync::Arc::new(<$type>::new($($args),*))
        ).clone()
    }
}

 fn single_mut() -> std::sync::Arc<std::sync::Mutex<$type>> {
    static mut POOL: core::option::Option<std::sync::Arc<std::sync::Mutex<$type>>> = None;
    unsafe {
        POOL.get_or_insert_with(move ||
            std::sync::Arc::new(std::sync::Mutex::new(<$type>::new($($args),*)))
        ).clone()
    }
}
}
    };
}
